/**
 * 左侧工具栏功能
 */
export default function PaletteProvider(palette, create, elementFactory, globalConnect, bpmnFactory) {
    this.create = create
    this.elementFactory = elementFactory
    this.globalConnect = globalConnect
    this.bpmnFactory = bpmnFactory

    palette.registerProvider(this)
}

PaletteProvider.$inject = [
    'palette',
    'create',
    'elementFactory',
    'globalConnect',
    'bpmnFactory',
    'globalConnect'
]

PaletteProvider.prototype.getPaletteEntries = function (element) {
    const {
        create,
        elementFactory,
        bpmnFactory,
        globalConnect
    } = this;

    // custom1，2，3分别标志不同形状，将businessObject挂在元素上，可以在renderer中通过element.businessObject.$attrs.custom读到，其他属性同理
    function createTask1() {
        return function (event) {
            const businessObject = bpmnFactory.create('bpmn:Task', { custom: 1, text:'', title: '', unit: '',conditions: '', standard:'',time:'', });
            console.log(businessObject, 'businessObject');
            const shape = elementFactory.createShape({
                type: 'bpmn:Task',
                businessObject
            });
            const label = elementFactory.createLabel();
            create.start(event, shape);

        }
    }

    function createTask2() {
        return function (event) {
            const businessObject = bpmnFactory.create('bpmn:Task', { custom: 2, text:'', conditions: '', standard:'',time:'', title: '', unit: '' });
            console.log(businessObject, 'businessObject');
            const shape = elementFactory.createShape({
                type: 'bpmn:Task',
                businessObject
            });
            const label = elementFactory.createLabel();
            create.start(event, shape);
        }
    }

    function createTask3() {
        return function (event) {
            const businessObject = bpmnFactory.create('bpmn:Task', { custom: 3, text: '', title: '', unit: '' });
            console.log(businessObject, 'businessObject');
            const shape = elementFactory.createShape({
                type: 'bpmn:Task',
                businessObject
            });
            const label = elementFactory.createLabel();
            create.start(event, shape);
        }
    }

    function createConnect() {
        return {
            group: 'tools',
            className: 'icon-custom icon-custom-flow',
            title: '新增线',
            action: {
                click: function (event) {
                    globalConnect.toggle(event)
                }
            }
        }
    }

    return {
        'create.lindaidai-task': {
            group: 'model',
            className: 'icon-custom lindaidai-task',
            title: '启动、完成类',
            action: {
                dragstart: createTask1(),
                click: createTask1()
            }
        },
        'create.rect-task': {
            group: 'model',
            className: 'icon-custom rect-task',
            title: '组织推进类',
            action: {
                dragstart: createTask2(),
                click: createTask2()
            }
        },
        'create.polygon-task': {
            group: 'model',
            className: 'icon-custom polygon-task',
            title: '决策类',
            action: {
                dragstart: createTask3(),
                click: createTask3()
            }
        },
        // 'global-connect-tool': createConnect()
    }
}